import axios from 'axios';
import MyToast from '@/components/mytoast'
// process是属于nodejs自带的模块，env是process下的一个属性
// NODE_ENV是自己添加的
console.log(process.env.NODE_ENV) // 打印现在的环境
// cnpm run start  ---- development   --- 开发环境
// cnpm run test ---- 测试环境
// cnpm run build ---- production  ---- 生产环境 - ---- 项目上线
const isDev = process.env.NODE_ENV === 'development';
// 不同的环境使用不同的接口
const baseURL = isDev ? "/api" : "http://74.100.59.24";
let request = axios.create({
  baseURL: baseURL
})

request.defaults.headers.common['token'] = localStorage.getItem('token');


request.interceptors.request.use(function (config) {
  // Do something before request is sent
  MyToast.info('请求')
  return config;
}, function (error) {
  // Do something with request error
  return Promise.reject(error);
});

// Add a response interceptor
request.interceptors.response.use(function (response) {
  // Do something with response data
  console.log('响应')
  return response;
}, function (error) {
  // Do something with response error
  return Promise.reject(error);
});

export default request;